package com.minimalist.basic.controller.basic;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.minimalist.basic.service.PostService;
import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.basic.vo.post.PostQueryVO;
import com.minimalist.common.entity.basic.vo.post.PostVO;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 11987
 */
@Validated
@RestController
@RequestMapping("/basic/post")
@Tag(name = "岗位管理")
public class PostController{

    @Autowired
    private PostService postService;

    @PostMapping("/addPost")
    @SaCheckPermission("basic:post:add")
    @Operation(summary = "添加岗位")
    public R<?> addPost(@RequestBody @Validated(Add.class) PostVO postVO){
        postService.addPost(postVO);
        return R.ok();
    }

    @DeleteMapping("/deletePostByPostId")
    @SaCheckPermission("basic:post:delete")
    @Operation(summary = "删除岗位 -> 根据岗位ID删除")
    public R<?> deletePostByPostId(
            @RequestParam("postId") @NotNull(message = "岗位ID不能为空")
            @Parameter(name = "postId", required = true, description = "岗位ID")
            Long postId){
        postService.deletePostByPostId(postId);
        return R.ok();
    }

    @PutMapping("/updatePostByPostId")
    @SaCheckPermission("basic:post:update")
    @Operation(summary = "修改岗位 -> 根据岗位ID修改")
    public R<?> updatePostByPostId(
            @RequestBody @Validated(Update.class) PostVO postVO){
        postService.updatePostByPostId(postVO);
        return R.ok();
    }

    @GetMapping("/getPagePostList")
    @SaCheckPermission("basic:post:get")
    @Operation(summary = "查询岗位列表(分页)")
    public R<PageResp<PostVO>> getPagePostList(PostQueryVO queryVO){
        return R.ok(postService.getPagePostList(queryVO));
    }

    @GetMapping("/getPostByPostId/{postId}")
    @SaCheckPermission("basic:post:get")
    @Operation(summary = "根据岗位ID查询岗位")
    public R<PostVO> getPostByPostId(
            @PathVariable(value = "postId")
            @NotNull(message = "岗位ID不能为空")
            @Parameter(name = "postId", description = "岗位ID", required = true)
            Long postId){
        return R.ok(postService.getPostByPostId(postId));
    }

}
